package mvp.cklm.testtask.main;

import mvp.cklm.testtask.service.AddressService;
import mvp.cklm.testtask.util.ConfigKeeper;
import mvp.cklm.testtask.util.ServiceKeeper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created with IntelliJ IDEA.
 * User: valera
 * Date: 25.02.14
 * Time: 10:28
 */
public class Main {
    private static final Logger log = LoggerFactory.getLogger(Main.class);


    public static void main(String[] args) {
        prepareDB();
        prepareServices();
        log.info("Preparation Done!");
        log.info("Start Demo!");
        Demo demo = new Demo();
        demo.demo();
        log.info("Demo finished!");
    }

    private static void prepareDB() {
        try {
            ConfigKeeper.initConnection("./config/db.properties");
        } catch (Exception e) {
            log.error("AHTUNG! Can't init DB {}", e);
        }
    }

    private static void prepareServices() {
        try {
            ServiceKeeper.registerService(new AddressService(ConfigKeeper.getClient(), ConfigKeeper.getDbName()));

        } catch (Exception e) {
            log.error("AHTUNG! Can't init services {}", e);
        }
    }


}
